package com.example.demo.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.entity.UserRole;
import com.example.demo.mapper.UserRoleMapper;
import com.example.demo.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 系统管理-用户和角色关联表 服务实现类
 * </p>
 *
 * @author vicente
 * @since 2024-01-24
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public List<Long> selectRoleIdByUserId(Long userId) {
        List<UserRole> userRoles = baseMapper.selectList(Wrappers.lambdaQuery(UserRole.class).eq(UserRole::getUserId, userId));
        //hutool格式转换Convert.toStr
        List<Long> list = userRoles.stream().map(item-> item.getRoleId()).collect(Collectors.toList());
        return list;
    }
}
